/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.Bookticket;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Sony
 */
public class BookticketHelper {
    Session session;
    public BookticketHelper(){
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public List<Bookticket> getAllBookticket(){
        List<Bookticket> lstBookticket = null;
        try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            Query q = this.session.createQuery("from Bookticket");
            lstBookticket = (List<Bookticket>)q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lstBookticket;
    }
    
    public void updateBookticket(Bookticket b){
         try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            this.session.save(b);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void deleteBookticket(Bookticket b){
        try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            this.session.delete(b);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
